--
-- Author: ping.wang
-- Date: 2018-07-13 17:39:48
--

local Item = require("app.public.dao.Item")
local Equip = require("app.public.dao.Equip")
local Jewel = require("app.public.dao.Jewel")

local fileName = string.getModeName(...)
local ClassRef = class(fileName)

function ClassRef:ctor(data)
	if data then
		self:initWithData(data)
	end
end

function ClassRef:initWithData(data)
	self._uuid = data.uuid  --拍卖行中商品的唯一ID
	--self._goodsId = data.goodsId --商品Id(对应auction_goods表里的ID字段)
	self._sellPrice = data.sellPrice --出售价格
	self._count = data.count --出售数量
	self._stamp = data.stamp --上架时间
	local item = nil
	local v = data.cell
	if v.item then
		item = Item.new(Enums.ItemBagType.item)
		item:read(v.item)
	end
	if v.equip then
		item = Equip.new()
		item:read(v.equip)
	end
	if v.jewel then
		item = Jewel.new()
		item:read(v.jewel)
	end
	self._item = item
	self._ownerUId = data.uid --卖家UID
end

function ClassRef:getProductUUId()
	return self._uuid
end

--获取单价
function ClassRef:getSellPrice()
	return self._sellPrice
end

--获取数量
function ClassRef:getCount()
	return self._count
end

--获取总价
function ClassRef:getTotalPrice()
	return self._sellPrice * self._count
end

--获取上架时间
function ClassRef:getTimeStamp()
	return self._stamp
end

--获取道具信息
function ClassRef:getItemData()
	return self._item
end

--判断是否是我出售的道具
function ClassRef:isMySellItem()
	return UD:getUid() == self._ownerUId
end

--获取离等待时间过去了多少秒 若小于0 则已经处于上架状态了
function ClassRef:getOutWaitTime()
	local waitTime = GD:getSystemPar( "auctionSaleWaitingTime" ) --上架等待时间
	local detalTime = self:getDeltaOnShelvesTime()
	return waitTime - detalTime
end

--获取离下架时间还有多少秒 若< 0 则应该下架了
function ClassRef:getOutSaleDurationTime()
	--local waitTime = GD:getSystemPar( "auctionSaleWaitingTime" ) --上架等待时间
	local durationTime = GD:getSystemPar( "auctionSaleDurationTime" ) --上架持续时间
	local detalTime = self:getDeltaOnShelvesTime()
	return durationTime - detalTime
end

function ClassRef:getDeltaOnShelvesTime()
	local curTime = math.floor(app.session:getServerTime() or app:getTime())
	return curTime - self._stamp
end

--获取距离等待上架时间的百分比
function ClassRef:getLastWaitTimePecent(time)
	local waitTime = GD:getSystemPar( "auctionSaleWaitingTime")
	if waitTime == 0 then return 0 end
	return math.floor(time/waitTime * 100)
end
--获取距离下架时间的百分比
function ClassRef:getLastOnShelvesTimePecent(time)
	local durationTime = GD:getSystemPar( "auctionSaleDurationTime")
	if durationTime == 0 then return 0 end
	return math.floor(time/durationTime * 100)
end
return ClassRef